package com.nicedistractions.roadtriptracker;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.content.Context;
import android.os.Environment;

public class Tools {
	
	private static final String TAG = "BACKUP";
	private static final String BACKUP_DIR = Environment.getExternalStorageDirectory() + "/RoadTripTracker";
	
	public static void writeLocation(double latitude, double longitude, Context ctx) {
		//Set the output location.
		File exportDir = new File(BACKUP_DIR);
		
		//If the output folder doesn't exist, create it.
		if (!exportDir.exists()) {
			exportDir.mkdirs();
		}
	   
		//Sort out a name.
		Calendar time = Calendar.getInstance();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_HHmm");		
		String fileName = formatter.format(time.getTime()) + ".txt";
				
		FileOutputStream fOut = null;
		try {
			FileWriter f = new FileWriter("/sdcard/download/impossible.txt");
			OutputStreamWriter osw = new OutputStreamWriter(fOut); 
			osw.write(latitude + " - " + longitude);
			osw.flush();
            osw.close();            
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
